package com.bsoft.exchange.service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bsoft.exchange.dao.his.DoctorMapper;
import com.bsoft.exchange.domain.Doctor;
import com.bsoft.exchange.domain.DoctorNumber;
import com.bsoft.exchange.util.DateUtil;

@Service
public class DoctorService {
	@Autowired
	DoctorMapper doctorMapper;
	
	
	
	public List<Doctor> selectList(String hospitalCode,String departmentCode,String scheduleDate,String doctorCode,String doctorType,int outpatientType,String lastModifyTime){
//		System.out.println("ddddddddddddd");
		Date startdate = null;
		Date enddate = null;
		Date now = null;
		Date yestday = null;
		int isnullDate = 0;
		
		now = new Date();
		yestday = DateUtil.addDateToDay(now,-1);
//		if(!scheduleDate.equals(null)){
		if(scheduleDate!=null&&!"".equals(scheduleDate)){
			
			isnullDate = 1;
			SimpleDateFormat strat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			try {
				startdate = strat.parse(scheduleDate+" 00:00:00");
				enddate = strat.parse(scheduleDate+" 23:59:59");
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
		List<Doctor> doctor = doctorMapper.selectList(hospitalCode, departmentCode,isnullDate, startdate, enddate,yestday,doctorCode,doctorType, outpatientType);
		for(int i = 0 ; i < doctor.size() ; i++) {
			  String doctorcode;
			  doctorcode = doctor.get(i).getDoctorId();
			  List<DoctorNumber> doctorNumber = doctorMapper.selectListNumber(hospitalCode,departmentCode,isnullDate, startdate, enddate,yestday,doctorcode);
			  doctor.get(i).setListSchedule(doctorNumber);;
//			  if(doctorNumber.size()==0){
//				  doctor.get(i).setSourceState("2");
//			  }
			}
		return doctor;
		
	}

}
